package com.stylefeng.guns.modular.platform.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.platform.model.UserTask;
import com.stylefeng.guns.modular.platform.service.IUserTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-26 17:55:44
 */
@Controller
@RequestMapping("/userTask")
public class UserTaskController extends BaseController {

    private String PREFIX = "/platform/userTask/";

    @Autowired
    private IUserTaskService userTaskService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userTask.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userTask_add")
    public String userTaskAdd() {
        return PREFIX + "userTask_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userTask_update/{userTaskId}")
    public String userTaskUpdate(@PathVariable Integer userTaskId, Model model) {
        UserTask userTask = userTaskService.selectById(userTaskId);
        model.addAttribute("item",userTask);
        LogObjectHolder.me().set(userTask);
        return PREFIX + "userTask_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userTaskService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserTask userTask) {
        userTaskService.insert(userTask);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer userTaskId) {
        userTaskService.deleteById(userTaskId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserTask userTask) {
        userTaskService.updateById(userTask);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userTaskId}")
    @ResponseBody
    public Object detail(@PathVariable("userTaskId") Integer userTaskId) {
        return userTaskService.selectById(userTaskId);
    }
}
